<?
// Get the vars from the javascript
if (!$_COOKIE['unique'] == 1)
{
$unique_visitor = 1;
setcookie ("unique", 1,time()+86400);

if ($_COOKIE['unique_num'] > 0)
{
$_COOKIE['unique_num'] = $_COOKIE['unique_num'] + 1;
setcookie ("unique_num", $_COOKIE['unique_num'],time()+60*60*24*365);
}
else
{
$_COOKIE['unique_num'] = 1;
setcookie ("unique_num", 1,time()+60*60*24*365);
}
	//Log Unique visitors per month
	if ($_GET['month'] < 10)
	{
	$meseca = $_GET['month'];
	}
	else
	{
	$meseca = $_GET['month'];
	}
	$unique_month = "log/unique/month/".$meseca;
	if (file_exists($unique_month))
	{
		$unique_hits_month = file ($unique_month);
		$unique_hits_month = $unique_hits_month[0] + 1;
		$unique_mnt = fopen ($unique_month,"w");
		fwrite ($unique_mnt,$unique_hits_month);
		fclose ($unique_mnt);
	}
	else
	{
		$unique_hits_month = $unique_hits_month[0] + 1;
		$unique_mnt = fopen ($unique_month,"a");
		fwrite ($unique_mnt,$unique_hits_month);
		fclose ($unique_mnt);
	}
	//Log Unique visitors per Year
	$unique_year = "log/unique/year/".$_GET['year'];
	if (file_exists($unique_year))
	{
		$unique_hits_year = file ($unique_year);
		$unique_hits_year = $unique_hits_year[0] + 1;
		$unique_yr = fopen ($unique_year,"w");
		fwrite ($unique_yr,$unique_hits_year);
		fclose ($unique_yr);
	}
	else
	{
		$unique_hits_year = $unique_hits_year[0] + 1;
		$unique_yr = fopen ($unique_year,"a");
		fwrite ($unique_yr,$unique_hits_year);
		fclose ($unique_yr);
	}
}
else
{
$unique_visitor = 0;
}
$res = $_GET['res'];
$avail_res = $_GET['avail'];
$color_depth = $_GET['color'];
$platform = $_GET['platform'];
$cpu = $_GET['cpu'];
// Do something with the info
//echo "You Screen's Resolution is $res, Your Available Screen Resolution is $avail_res, and the Color Depth on your screen is $color_depth.";
$width = $res;
$height = $avail_res;
$color = $color_depth;
$language = $_GET['language'];
$host = $_GET['host'];
$ref = $_GET['ref'];
$url = $_GET['url'];
$browser = $_GET['browser'];
$remadr = $_GET['remadr'];
$remhos = $_GET['remhos'];
$year = $_GET['year'];
$month = $_GET['month'];
$month_name = $_GET['month_name'];
$day_week = $_GET['day_week'];
$week = $unique_visitor.".".$_COOKIE['unique_num'];
$day = $_GET['day'];
$hour = $_GET['hour'];
$minute = $_GET['minute'];
$second = $_GET['second'];
$day_of_year = $_GET['day_of_year'];
$uri = $_GET['uri'];
$unique = $browser.$remadr."\n";

if  ($day<10)
{
$fb = fopen ("log/".$year."_".$month."_".$day.".bin", "a");
}
else
{
$fb = fopen ("log/".$year."_".$month."_".$day.".bin", "a");
}
fputs($fb, 1);
fclose($fb);
$hits = filesize("log/".$year."_".$month."_".$day.".bin");

$array = array("\n",$hits,$cpu,$platform,$width,$height,$color,$language,$host,$url,$ref,$browser,$remadr,$remhos,$year,$month,$month_name,$day_week,$week,$day,$hour,$minute,$second,$day_of_year);
$separated = implode("|", $array);
$fail = fopen("log/".$year."_".$month."_".$day.".log" , "a+");
fwrite($fail,$separated);
fclose($fail);

//Log OS
if (preg_match ("/win/i", $platform)) {
				if (preg_match ("/NT 5.1/i", $browser)) {
				$platform_file = "log/os/winxp";
				} else {
				$platform_file = "log/os/win98";
				}}
				else {
				if (preg_match ("/linux/i", $browser)) {
				$platform_file = "log/os/linux";
				} else {
				if (preg_match ("/bsd/i", $browser)) {
				$platform_file = "log/os/bsd";
				} else {
				if (preg_match ("/mac/i", $browser)) {
				$platform_file = "log/os/mac";
				} else {
				if (preg_match ("/sunos/i", $browser)) {
				$platform_file = "log/os/sunos";
				} else {
				if (preg_match ("/irix/i", $browser)) {
				$platform_file = "log/os/irix";
				} else {
				if (preg_match ("/beos/i", $browser)) {
				$platform_file = "log/os/beos";
				} else {
				if (preg_match ("/os\/2/i", $browser)) {
				$platform_file = "log/os/os2";
				} else {
				$platform_file = "log/os/unknown";
				}
				}
				}
				}
				}
				}
				}
				}
		$aidi = fopen($platform_file,"a");
		fwrite($aidi,1);
		fclose($aidi);
		
		//Log browser
		if (preg_match ("/avant/i", $browser)) {
		$browser_file="log/browser/avant";
		} else {
		if (preg_match ("/opera/i", $browser)) {
		$browser_file="log/browser/opera";
		} else {
		if (preg_match ("/Konqueror/i", $browser)) {
		$browser_file="log/browser/konqueror";
		} else {
		if (preg_match ("/netscape/i", $browser)) {
		$browser_file="log/browser/netscape";
		} else {
		if (preg_match ("/mac/i", $browser)) {
		$browser_file="log/browser/mac";
		} else {
		if (preg_match ("/MSIE 6.0/i", $browser)) {
		$browser_file="log/browser/ie";
		} else {
		if (preg_match ("/MSIE 4.0/i", $browser)) {
		$browser_file="log/browser/ie4";
		} else {
		if (preg_match ("/MSIE 5.0/i", $browser)) {
		$browser_file="log/browser/ie4";
		} else {
		if (preg_match ("/MSIE 5.1/i", $browser)) {
		$browser_file="log/browser/ie";
		} else {
		if (preg_match ("/MSIE 5.5/i", $browser)) {
		$browser_file="log/browser/ie";
		} else {
		if (preg_match ("/mozilla\/4/i", $browser)) {
		$browser_file="log/browser/mozilla4";
		} else {
		if (preg_match ("/mozilla\/5/i", $browser)) {
		$browser_file="log/browser/mozilla5";
		} else {
		$browser_file="log/browser/unknown";
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		$mali = fopen($browser_file,"a");
		fwrite($mali,1);
		fclose($mali);
		
		//Log Screen Resolution
		if (preg_match ("/640/i", $res)) {
		$res_file="log/res/640";
		} else {
		if (preg_match ("/800/i", $res)) {
		$res_file="log/res/800";
		} else {
		if (preg_match ("/1024x768/i", $res)) {
		$res_file="log/res/1024";
		} else {
		if (preg_match ("/1152/i", $res)) {
		$res_file="log/res/1152";
		} else {
		if (preg_match ("/1280/i", $res)) {
		$res_file="log/res/1280";
		} else {
		if (preg_match ("/1600/i", $res)) {
		$res_file="log/res/1600";
		} else {
		$res_file="log/res/unknown";
		}
		}
		}
		}
		}
		}
		$vai = fopen($res_file,"a");
		fwrite($vai,1);
		fclose($vai);
		//Log average hour
		if (file_exists("log/hourstats/$hour"))
			{
			$hits_hour = file("log/hourstats/$hour");
			$hits_hour = $hits_hour[0] + 1;
			$hour_file = fopen ("log/hourstats/$hour", "w"); 
			fputs($hour_file, $hits_hour);
			fclose($hour_file);
			}
		else
			{
			$hits_hour = $hits_hour[0] + 1;
			$hour_file = fopen ("log/hourstats/$hour", "w"); 
			fputs($hour_file, $hits_hour);
			fclose($hour_file);
			}
		//Log country
		preg_match("/[^\.\/]+\.[^\.\/]+$/",$remhos,$matches);
									if (is_numeric($matches[0]))
										{
										if (preg_match ("/bg/i", $language)) {
										$flag = "bg";
										} else {
										if (preg_match ("/en/i", $language)) {
										$flag = "us";
										} else {
										if (preg_match ("/nl/i", $language)) {
										$flag = "nl";
										} else {
										if (preg_match ("/be/i", $language)) {
										$flag = "be";
										} else {
										if (preg_match ("/ru/i", $language)) {
										$flag = "ru";
										} else {
										if (preg_match ("/cz/i", $language)) {
										$flag = "cz";
										} else {
										if (preg_match ("/it/i", $language)) {
										$flag = "it";
										} else {
										if (preg_match ("/fr/i", $language)) {
										$flag = "fr";
										} else {
										if (preg_match ("/tr/i", $language)) {
										$flag = "tr";
										} else {
										if (preg_match ("/pl/i", $language)) {
										$flag = "pl";
										} else {
										if (preg_match ("/au/i", $language)) {
										$flag = "au";
										} else {
										if (preg_match ("/mx/i", $language)) {
										$flag = "mx";
										} else {
										if (preg_match ("/es/i", $language)) {
										$flag = "es";
										} else {
										if (preg_match ("/ro/i", $language)) {
										$flag = "ro";
										} else {
										if (preg_match ("/gr/i", $language)) {
										$flag = "gr";
										} else {
										if (preg_match ("/de/i", $language)) {
										$flag = "de";
										} else {
										$flag = "unknown";
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
										}
									else
									{
										$host = $matches[0];
										$Tnat = explode(".", $host);
									$flag=$Tnat[1];
									}
		switch($flag)
		{
			case "com":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "us";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "com";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
			case "":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "unknown";break;
				}				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
			case "net":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "net";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "Net":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "net";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "NET":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "net";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "biz":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "biz";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "edu":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "edu";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "gov":
				if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "gov";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            case "org":
                if (preg_match ("/bg/i", $language)) {
				$flag = "bg";break;
				} else {
				if (preg_match ("/en/i", $language)) {
				$flag = "uk";break;
				} else {
				if (preg_match ("/nl/i", $language)) {
				$flag = "nl";break;
				} else {
				if (preg_match ("/be/i", $language)) {
				$flag = "be";break;
				} else {
				if (preg_match ("/ru/i", $language)) {
				$flag = "ru";break;
				} else {
				if (preg_match ("/cz/i", $language)) {
				$flag = "cz";break;
				} else {
				if (preg_match ("/it/i", $language)) {
				$flag = "it";break;
				} else {
				if (preg_match ("/fr/i", $language)) {
				$flag = "fr";break;
				} else {
				if (preg_match ("/tr/i", $language)) {
				$flag = "tr";break;
				} else {
				if (preg_match ("/pl/i", $language)) {
				$flag = "pl";break;
				} else {
				if (preg_match ("/au/i", $language)) {
				$flag = "au";break;
				} else {
				if (preg_match ("/mx/i", $language)) {
				$flag = "mx";break;
				} else {
				if (preg_match ("/es/i", $language)) {
				$flag = "es";break;
				} else {
				if (preg_match ("/ro/i", $language)) {
				$flag = "ro";break;
				} else {
				if (preg_match ("/gr/i", $language)) {
				$flag = "gr";break;
				} else {
				if (preg_match ("/de/i", $language)) {
				$flag = "de";break;
				} else {
				$flag = "org";break;
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
				}
            default:
				$flag = $flag; break;
		}
		
		$country_file = "log/country/$flag";
		if (file_exists($country_file))
		{	
		$handler = file ($country_file);
		$handler = $handler[0] + 1;
		$zapis = fopen ($country_file,"w");
		fwrite ($zapis,$handler);
			}
		else
		{
		$handler = $handler[0] + 1;
		$zapis = fopen ($country_file,"w");
		fwrite ($zapis,$handler);
		}
?>
